# coding=utf-8
from fastapi import HTTPException
from sqlalchemy.orm import Session
from 学生管理系统.Mondel.Eployment_model import Eployment
from 学生管理系统.Query.Eployment import Eployment1


# 查询所有学生
def get_query(db: Session):
    return db.query(Eployment).all()

# 查询学生编号，返回指定学生结果集
def get_one_query(db: Session, student_id: int):
    return db.query(Eployment).filter(Eployment.student_id == student_id).first()


# 根据学生编号，公司名称，薪资范围，查询就业信息
def get_student_message(db: Session, student_id: int, company_name: str, salary: int):
    return db.query(Eployment).filter(Eployment.student_id == student_id,Eployment.company == company_name,Eployment.salary == salary).first()


# 添加学?就业信息
def get_job_add(db: Session, emp: Eployment1):
    emp1 = Eployment(**emp.dict())
    db.add(emp1)
    db.commit()
    db.refresh(emp1)
    return emp1


# 修改学生就业信息
def get_job_update(db: Session, emp: Eployment1):
    emp2 = Eployment1(**emp.dict())
    db.query(Eployment).filter(Eployment.id == emp2.student_id).update(emp.dict())
    db.commit()
    return emp2


# 删除学生就业信息
def get_job_delete(db: Session, student_id: int):
    # 先查询实例
    del_stu = db.query(Eployment).filter(Eployment.id == student_id).first()
    # 删除查询到的实例
    db.delete(del_stu)
    db.commit()

    return {
        "message": f"就业记录ID {student_id} 已删除",
        "deleted_id":student_id
    }

